/**
 * 乘法(处理小数运算精度问题)
 * 思路: 0.215 * 0.3 === ((0.215 * 1000) * (0.3 * 10)) / (1000 * 10) === (215 * 3) / (Math.pow(10,3) * Math.pow(10,1))
 * @param {String | Number} 乘数，可传多个
 * @return {Number}
*/
function multiply(...args) {
  const numStrings = [...args].map(num => (num ?? '').toString())
  const ints = numStrings.map(str => parseInt(str.replace('.', '')))
  const ratios = numStrings.map(str => Math.pow(10, str.split('.')[1]?.length || 0))

  const intsTotal = ints.reduce((total, int) => total * (Number(int) || 0), 1)
  const ratiosTotal = ratios.reduce((total, radio) => total * (Number(radio) || 0), 1)

  return intsTotal / ratiosTotal
}

// // 测试
// multiply(7.21, 13)
// console.log(multiply(7.21, 13))
// // 93.73
// const arr = [1.2, 3.13, 2.18, 4]
// multiply(...arr)
// console.log(multiply(...arr))
// // 32.75232

